//
//  RadioListController.m
//  宝宝儿歌
//
//  Created by student on 16/4/23.
//  Copyright © 2016年 baobaoerge. All rights reserved.
//

#import "RadioListController.h"

#import "RadioDetailViewController.h"
#import "RadioModel.h"
#import "RadioGroupModel.h"

#import "BlurImageView.h"

#import "ModelSingleton.h"
#import "ModelGroupListInfo.h"
#import <UIImageView+WebCache.h>
//cell的模型
#import "FMListCell.h"

@interface RadioListController()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong)NSArray *list;
@property (nonatomic, strong)UITableView *tableView;

@end

@implementation RadioListController

- (void)viewDidLoad {
    
    BlurImageView *imageView = [[BlurImageView alloc] initWithFrame:self.view.bounds];
    [imageView refreshBackgroundBlurView];
//    [self.view addSubview:imageView];
    [self.view addSubview:self.tableView];

    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    self.tableView = tableView;
    self.tableView.backgroundView = imageView;
    [self.view addSubview:self.tableView];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"radioListCell"];
    //更改注册
     [self.tableView registerClass:[FMListCell class] forCellReuseIdentifier:@"radioListCell"];
    NSString *str = @"http://www.ximalaya.com/dq/kid-%E5%84%BF%E6%AD%8C%E5%A4%A7%E5%85%A8/";
    [ModelGroupListInfo modelGroupListInfo:str successBlok:^(NSArray *imgList) {
        self.list = imgList;
        [self.tableView reloadData];
    } failBlok:^(NSError *error) {
        
    }];
    
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FMListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"radioListCell" forIndexPath:indexPath];
    
    NSDictionary *dict =self.list[indexPath.row];
    RadioGroupModel *radioGroupModel = [RadioGroupModel radioGroupModelWithDictionary:dict];
    
//    //修改界面byClement
//    //圆角
//    cell.imageView.layer.cornerRadius = 30;
//    //设置边框
//    cell.imageView.layer.borderWidth = 0.6;
//    cell.imageView.layer.borderColor = [UIColor orangeColor].CGColor;
//    //设置图片填充
//    cell.imageView.contentMode = UIViewContentModeScaleToFill;
//    //切割多余部分
//    cell.imageView.layer.masksToBounds = YES;
//    //
//    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:radioGroupModel.radioGroupImage] placeholderImage:[UIImage imageNamed:@"placeholder"]];
//    NSLog(@"%@",dict);
//    
//    
//    cell.textLabel.text = radioGroupModel.radioGroupTitle;
//    NSLog(@"%@",cell.textLabel.text);
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:radioGroupModel.radioGroupImage] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    //    NSLog(@"%@",dict);
    //
    //
        cell.nameLabel.text = radioGroupModel.radioGroupTitle;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dict = self.list[indexPath.row];
    RadioGroupModel *radioGroupModel = [RadioGroupModel radioGroupModelWithDictionary:dict];
    RadioDetailViewController *rdVC = [[RadioDetailViewController alloc]init];
    rdVC.radioModelLink = radioGroupModel.radioGroupLink;
    rdVC.radioImage = radioGroupModel.radioGroupImage;
    [self.navigationController pushViewController:rdVC animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;

}



@end
